package com.hongxin.nw.netty.model.packing.info;

import com.hongxin.nw.netty.utils.FieldPack;
import com.hongxin.nw.netty.values.TypeIdentif;
import lombok.extern.slf4j.Slf4j;

/**
 * @remark A.25远程启动充电
 * @author: GuoXiaolin
 * @date 2019/5/25 15:42
 * @Version 1.0
 * @Descibe
 */
@Slf4j
public class Csdna1_12 implements IPacking {

    private String co ;//充电设备编号
    private String bj ;//充电设备为一桩多充时用来标记接口号，一桩一充时此项为0。多个接口时顺序对每个接口进行编号
    private String ye ;//单位元，精确到0.01
    private String uid;//用户身份ID（8字节BCD码）,
    private String cType;//充电方式（1字节BCD码），00 自动；01 按电量；02 按时间；03 按金额
    private String cParam;//待充电参数（电量/时间，3字节BCD码）；
//    电量：单位kWh，精确到0.01
//    时间：单位min，精确到0.01
//    金额：单位 元，精确到0.01
    @Override
    public String packing() {
        String sb2 = this.uid + this.cType + this.cParam;
        return this.co + this.bj + this.ye + sb2;
    }

    public Csdna1_12 setCo(String co) {
        this.co = FieldPack.caseToBCD(co, TypeIdentif.BYTE_CO.getByteLength());
        return this;
    }

    public Csdna1_12 setBj(String bj) {
        this.bj = FieldPack.caseToBin(bj, TypeIdentif.BYTE_CHARGE_INTERFACE_IDENTIFY.getByteLength());
        return this;
    }

    public Csdna1_12 setYe(double ye) {
        this.ye = FieldPack.decimalToHex(ye, 2, TypeIdentif.BYTE_MONEY.getByteLength());
        return this;
    }

    public Csdna1_12 setUid(String uid) {
        this.uid = FieldPack.caseToBCD(uid, TypeIdentif.BYTE_USER_ID.getByteLength());
        return this;
    }

    public Csdna1_12 setCType(String cType) {
        this.cType = FieldPack.caseToBCD(cType, TypeIdentif.BYTE_CHARGE_TYPE.getByteLength());
        return this;
    }

    public Csdna1_12 setCParam(double cParam) {
        this.cParam = FieldPack.decimalToHex(cParam, 2, TypeIdentif.BYTE_CHARGE_PARAM.getByteLength());
        return this;
    }

    @Override
    public String toString() {
        return "Csdna1_12{" +
                "co='" + co + '\'' +
                ", bj='" + bj + '\'' +
                ", ye='" + ye + '\'' +
                ", uid='" + uid + '\'' +
                ", cType='" + cType + '\'' +
                ", cParam='" + cParam + '\'' +
                '}';
    }
}
